package com.snopy.designPattern.chainOfResponsibility.impl;

import com.snopy.designPattern.chainOfResponsibility.inter.Middleware;
import lombok.extern.slf4j.Slf4j;

import java.util.HashMap;

/**
 * @author snopy
 * @version 1.0.0
 * @classname Server
 * @description
 * @email 77912204@qq.com
 * @date 2022/03/04 13:16
 */
@Slf4j
public class Server {
    private HashMap<String,String> users = new HashMap<>();
    private Middleware middleware;

    public void setMiddleware(Middleware middleware) {
        this.middleware = middleware;
    }

    public boolean login(String username,String password){
        if (middleware.check(username,password)){
            log.info("Authorization have been successful!");
            return true;
        }
        return false;
    }
    public void register(String username,String password){
        users.put(username,password);
    }

    public boolean hasUsername(String username){

        return users.containsKey(username);
    }
    public boolean isValidPassword(String username,String password){
        return users.get(username).equals(password);
    }
}
